/**
 * 模块列表页JS
 * @type {string}
 */

function reloadTable() {
    setTimeout(function () {
        let tableBase = layui.index;
        tableBase.refresh()
    }, 500)
}

function statuRefresh() {
    let tableBase = layui.index;
    tableBase.statuRefresh()
}

const _delete = function (params) {
    if (params) {
        layer.confirm('确定要删除吗？', {icon: 3, title: '提示'}, function (index) {
            layer.close(index);
            // 打开一个加载层
            var loadIndex = layer.msg('加载中', {
                icon: 16,
                shade: 0.5
            });
            $.post(__basePath + tabUrl() + "/delete", {_ids: params}, function (data) {
                layer.close(loadIndex)
                if (data.code > 0) {
                    layer.msg(data.msg, {icon: 1});
                    reloadTable();
                } else  if(data.code !== -2) {
                    layer.msg(data.msg, {icon: 5});
                }
            }, 'json').fail(function () {
                layer.close(loadIndex)
                layer.msg('请求失败，请稍后再试！', {icon: 5});
            });
        });
    } else {
        layer.msg('请勾选操作项!', {icon: 0});
    }
}

const _destroy = function (params) {
    console.log(params);
    if (params) {
        layer.confirm('确定要销毁吗？', {icon: 3, title: '提示'}, function (index) {
            layer.close(index);
            // 打开一个加载层
            var loadIndex = layer.msg('加载中', {
                icon: 16,
                shade: 0.5
            });
            $.post(__basePath + tabUrl() + "/destroy", {_ids: params}, function (data) {
                console.log(data)
                layer.close(loadIndex)
                if (data.code > 0) {
                    layer.msg(data.msg, {icon: 1});
                    reloadTable();
                } else if(data.code !== -2) {
                    layer.msg(data.msg, {icon: 5});
                }
            }, 'json').fail(function () {
                layer.close(loadIndex)
                layer.msg('请求失败，请稍后再试！', {icon: 5});
            });
        });
    } else {
        layer.msg('请勾选操作项!', {icon: 0});
    }

}

const _disable = function (title, params) {
    if (params) {
        layer.confirm('确定要' + title + '吗？', {icon: 3, title: '提示'}, function (index) {
            layer.close(index);
            // 打开一个加载层
            var loadIndex = layer.msg('加载中', {
                icon: 16,
                shade: 0.5
            });
            $.post(__basePath + tabUrl() + "/status", {_ids: params}, function (data) {
                layer.close(loadIndex)
                if (data.code > 0) {
                    layer.msg(data.msg, {icon: 1});
                    statuRefresh();
                } else  if(data.code !== -2) {
                    layer.msg(data.msg, {icon: 5});
                }
            }, 'json').fail(function () {
                layer.close(loadIndex)
                layer.msg('请求失败，请稍后再试！', {icon: 5});
            });
        });
    } else {
        layer.msg('请勾选操作项!', {icon: 0});
    }
}
